#include <iostream>
#include <unistd.h>
// #include "include/gen.hpp"
#include "include/calc.hpp"
using namespace std;

char fuhao[] = {'+','-','*','/'};
// 2 3 4
// 式子随机长度
int rand_len(){
    return rand()%3+2;
}
char rand_fuhao(){
    
    return fuhao[rand()%4];
}

string bad_generator(){
    
    // srand(time(0));
    int len = rand()%3+2;
    string result="";
    for(int i=0;i<len;i++){
        fenshu a;
        result+=a.to_string();
        if(i!=len-1){
            result.push_back(fuhao[rand()%4]);
        }
    }
    // cout<<result<<endl;

    return result;
}

string check_gen(){
    while(1){
        // cout<<"before ";
        string shizi = bad_generator();
        // cout<<shizi<<endl;
        try{
            fenshu result = calc(shizi);
            return shizi;
        }
        catch(const char* msg){
            cout<<msg<<endl;
        }
        // cout<<" after calculate\n";
        // sleep(1);
        // srand(time(0));
    }


}

string general = "if you want the ans, input\"yes\"\nif don\'t input \"no\"\n";

int main(){
    srand(time(0));
    // for(int i=0;i<10;i++){
    //     cout<<bad_generator()<<endl;
    // }
    while(1){
        system("clear");
        string shizi = check_gen();
        cout<<shizi<<endl;
        cout<<general;
        string ans;
        cin>>ans;
        while(1){
            if(ans=="yes"){
                cout<<calc(shizi).to_string()<<endl;
                cout<<"continue?"<<endl;
                cin >> ans;
                
                break;
            }
            else if(ans=="no"){
                break;
            }
            else{
                cout<<general;
                cin>>ans;
            }
        }
    }

    string shizi = check_gen();
    cout<<shizi<<endl;
    return 0;
}